package com.servlet.users;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.ListIterator;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.UsersDAO;
import com.entity.Users;

public class BGLoginServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String userName = request.getParameter("user_name");
		String userPassword = request.getParameter("user_password");
		UsersDAO usersDAO = new UsersDAO();
		Users users = usersDAO.findById(1);//数据库第一条记录为后台管理员信息

		if (users.getUser_name().equals(userName)
				&& users.getUser_password().equals(userPassword)) {
			request.getRequestDispatcher("/background/index.jsp").forward(request,
					response);
			return;

		}
		request.getRequestDispatcher("/background/bglogin.jsp").forward(request, response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String userName = request.getParameter("user_name");
		String userPassword = request.getParameter("user_password");
		UsersDAO usersDAO = new UsersDAO();
		Users users = usersDAO.findById(1);//数据库第一条记录为后台管理员信息

		if (users.getUser_name().equals(userName)
				&& users.getUser_password().equals(userPassword)) {
			request.getRequestDispatcher("/background/index.jsp").forward(request,
					response);
			return;

		}
		request.getRequestDispatcher("/background/bglogin.jsp").forward(request, response);


	}

}
